import java.io.*;
import java.util.*;
public class goodslist {
    public static void main(String args[]) {
        File file = new File("C:/Users/lenovo/IdeaProjects/untitled9/out/production/untitled9/goodslist.txt");
        Scanner sc = null;
        int count = 0;
        double sum = 0;
        try {
            double score = 0;
            sc = new Scanner(file);
            sc.useDelimiter("[^0123456789.a-zA-Z ]+");
            while (sc.hasNextDouble()) {
                score = sc.nextDouble();
                count++;
                sum = sum + score;
                System.out.println("商品价格:" + (int) score + " /台");
            }
            double aver = sum / count;
            String str = String.format("%d", (int) aver);
            System.out.println("平均价格:" + str + " /台");
            FileWriter fw = new FileWriter(file, true); 
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write("平均价格: " + str + " /台\n");
            bw.close();
        } catch (Exception exp) {
            System.out.println(exp);
        }
    }
} 

